package router

import (
	"226zy/client/client"
	"226zy/client/enit"
	"226zy/common/proto/user"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Login(c *gin.Context) {
	var data enit.User
	err := c.ShouldBind(&data)
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": http.StatusInternalServerError,
			"Data": err.Error(),
		})
		return
	}
	login, err := client.Login(c, &user.LoginReq{
		Name:     data.Phone,
		Password: data.Password,
	})
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": http.StatusInternalServerError,
			"Data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, &gin.H{
		"code": http.StatusOK,
		"data": login,
	})
}

func List(c *gin.Context) {
	list, err := client.List(c, &user.ListReq{})
	if err != nil {
		c.JSON(http.StatusInternalServerError, &gin.H{
			"code": http.StatusInternalServerError,
			"Data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, &gin.H{
		"code": http.StatusOK,
		"data": list,
	})
}
